import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/enum/app_enum.dart';
import 'package:yysk_app/pages/main/dao/dao.dart';
import 'package:yysk_app/pages/main/home/home_page.dart';
import 'package:yysk_app/pages/main/build_page_view.dart';
import 'package:yysk_app/pages/main/main_controller.dart';
import 'package:yysk_app/pages/main/market/market_page.dart';
import 'package:yysk_app/pages/main/mine/mine_page.dart';
import 'package:yysk_app/pages/main/mine/settingDrawer.dart';
import 'package:yysk_app/routes/global_controller.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:yysk_app/widget/image_asset_widget.dart';

// ignore: must_be_immutable
class MainPage extends StatelessWidget {
  static const path = '/main';
  MainPage({super.key});

  final controller = Get.put(MainController());
  final globaController = Get.put(GlobalController());
  Map<String, dynamic> statusMap = {
    'homePage': const HomePage(),
    'myPage': MinePage(),
  };

  @override
  Widget build(BuildContext context) {
    // consoleLog(statusMap.map(convert))

    return PopScope(
      canPop: false, // 直接禁用返回手势（包括物理返回键）
      child: Scaffold(
        key: controller.mainScaffoldKey,
        drawer: settingDrawer(context,globaController),
        body: Container(
          padding: EdgeInsets.zero,
          child: Obx(() {
            return PageView(
              controller: controller.pageController,
              physics: const NeverScrollableScrollPhysics(),
              children: [
                BuildPageView(
                  hasAuth: globaController.hasAuth.value,
                  hasWallet: controller.hasWallet.value,
                  child: const HomePage(),
                ),
                BuildPageView(
                  hasAuth: true,
                  hasWallet: controller.hasWallet.value,
                  showRob:true,
                  child: MarketPage(),
                ),
                BuildPageView(
                  hasAuth: globaController.hasAuth.value,
                  hasWallet: controller.hasWallet.value,
                  child: DaoPage(),
                ),
                BuildPageView(
                  hasAuth: globaController.hasAuth.value,
                  hasWallet: controller.hasWallet.value,
                  child: MinePage(),
                ),
              ],
            );
          }),
        ),
        bottomNavigationBar: Obx(
          () => Material(
            color: AppColors.backgroundColor,
            elevation: 8.0,
            // shadowColor: Colors.grey.withOpacity(0.4),
            child: Container(
              clipBehavior: Clip.antiAlias,
              decoration: BoxDecoration(),
              child: BottomNavigationBar(
                fixedColor: AppColors.fontColor,
                unselectedItemColor: AppColors.fontColorGrey,
                backgroundColor: AppColors.backgroundColorBlack,
                currentIndex: controller.currentIndex.value,
                selectedFontSize: 12,
                enableFeedback: false,
                onTap: (index) {
                  controller.changeIndex(index: index);
                },
                type: BottomNavigationBarType.fixed,
                // selectedItemColor: const Color(0xFFFFFFFF),
                items: [
                  _bottomItem('首页', Icons.home, 0),
                  _bottomItem('市场', Icons.account_circle, 1),
                  _bottomItem('DAO', Icons.account_circle, 2),
                  _bottomItem('我的', Icons.account_circle, 3),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }

  _bottomItem(String title, IconData icon, int index) {
    return BottomNavigationBarItem(
      icon: Container(
        margin: const EdgeInsets.only(top: 0),
        child: ImageAssetWidget(
          imageUrl: 'static/images/tabbar/main_bar_$index@2x.png',
          width: 24.px,
          height: 24.px,
        ),
      ),
      activeIcon: ImageAssetWidget(
        imageUrl: 'static/images/tabbar/main_bar_actived_$index@2x.png',
        width: 24.px,
        height: 24.px,
      ),
      label: title,
    );
  }
}
